package com.example.controller;

import com.github.pagehelper.PageInfo;
import com.example.common.Result;
import com.example.entity.Expenses;
import com.example.entity.ProcessingRecords;
import com.example.service.ProcessingRecordsService;
import com.example.service.ProcessingRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description TODO
 * @Author dingchunlin
 * @Date 2023/12/28 15:55
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/processingRecords")
public class ProcessingRecordsController {
    

    @Autowired
    private ProcessingRecordsService processingRecordsService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody ProcessingRecords processingRecords) {
        processingRecordsService.add(processingRecords);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        processingRecordsService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        processingRecordsService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody ProcessingRecords processingRecords) {
        processingRecordsService.updateProcessingRecords(processingRecords);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        ProcessingRecords processingRecords = processingRecordsService.selectById(id);
        return Result.success(processingRecords);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(ProcessingRecords processingRecords ) {
        List<ProcessingRecords> list = processingRecordsService.selectAll(processingRecords);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(ProcessingRecords processingRecords,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<ProcessingRecords> page = processingRecordsService.selectPage(processingRecords, pageNum, pageSize);
        return Result.success(page);
    }

    /**
     * 根据当前登录用户查询待审核的订单
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/getExpensesById")
    public Result getExpensesById(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                  @RequestParam(required = false) String expensesType){
        PageInfo<ProcessingRecords> page = processingRecordsService.getExpensesById(pageNum, pageSize,expensesType);
        return Result.success(page);
    }


}
